#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int num[1 << 20];
int dp[1 << 20];
int cnt[25][N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) {
    rep(j, 0, m - 1) cnt[j][i] = cnt[j][i - 1];
    int x;
    cin >> x;
    x--;
    cnt[x][i]++;
  }
  int mx = (1 << m) - 1;
  rep(s, 1, mx) {
    rep(i, 0, m - 1) {
      if (!(s & (1 << i))) continue;
      int t = s ^ (1 << i);
      num[s] = num[t] + cnt[i][n];
      dp[s] = max(dp[s], dp[t] + cnt[i][num[s]] - cnt[i][num[t]]);
    }
  }
  cout << n - dp[mx];
  return 0;
}